NAME   = test_lpc2138

CC      = arm-elf-gcc
LD      = arm-elf-ld -v
AR      = arm-elf-ar
AS      = arm-elf-as
CP      = arm-elf-objcopy
OD		= arm-elf-objdump
SIZE	= arm-elf-size

ARM_LIBS = "C:\GNUARM\arm-elf\lib"
GCC_LIBS = "C:\GNUARM\lib\gcc\arm-elf\4.3.2"

GCC_INCS = "C:\GNUARM\arm-elf\include"
GCC_LIBM = "C:\GNUARM\arm-elf\lib"
GCC_LIBI = "C:\GNUARM\arm-elf\lib\interwork"

CFLAGS  = -I./ -I./include  -c -fno-common -O0 -g -mcpu=arm7tdmi
AFLAGS  = -ahls -mapcs-32 -mcpu=arm7tdmi -o crt.o
LFLAGS  = -Map ./release/${NAME}.map -T./config/lpc2138-FLASH.ld
CPFLAGS = -O ihex
ODFLAGS	= -x --syms

all: build size

clean:
	-rm ./release/cpu/crt.lst
	-rm ./release/main.lst 
	-rm ./release/main.o 
	-rm ./release/main.out 
	-rm ./release/system.o
	-rm ./release/delay.o	
	-rm ./release/${NAME}.hex 
	-rm ./release/${NAME}.map 
	-rm ./release/${NAME}.dmp

size:
	@ echo "Size of Generated Hex File is "
	$(SIZE) --target=ihex -t ./release/${NAME}.hex

build: main.out
	@ echo "...copying"
	$(CP) $(CPFLAGS) ./release/main.out ./release/${NAME}.hex
	$(OD) $(ODFLAGS) ./release/main.out > ./release/${NAME}.dmp

main.out: crt.o delay.o main.o system.o io.o  ./config/lpc2138-FLASH.ld 
	@ echo "..linking"
	$(LD) $(LFLAGS) -o ./release/main.out ./release/cpu/crt.o ./release/cpu/io.o ./release/delay.o ./release/system.o ./release/main.o -L$(GCC_LIBS) -L$(ARM_LIBS) -lm -lc -lgcc 

crt.o: ./src/cpu/crt.s
	@ echo ".assembling crt.s"
	$(AS) $(AFLAGS) ./src/cpu/crt.s > ./release/cpu/crt.lst -o ./release/cpu/crt.o

main.o: ./src/main.c
	@ echo ".compiling"
	$(CC) $(CFLAGS) ./src/main.c -o ./release/main.o
	
delay.o: ./src/delay.c
	@ echo ".compiling delay"
	$(CC) $(CFLAGS) ./src/delay.c -o ./release/delay.o	
	
system.o: ./src/system.c
	@ echo ".compiling system"
	$(CC) $(CFLAGS) ./src/system.c -o ./release/system.o	
	
io.o: ./src/cpu/io.c
	@ echo ".compiling io"
	$(CC) $(CFLAGS) ./src/cpu/io.c -o ./release/cpu/io.o		
	
									